{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 微分方程模型\n",
    "\n",
    "**用sympy和scipy**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXxU9b3/8dcHwhaWIISENQmr7GsIi0tV3NHiLggIiOLSant7f63W5dar3lbb3qpdvMoVAQkguCBc61KK4lYTCPu+k4QQSFgSlpD9+/tj5rZcGzVkJjmZmffz8chjtjM5n29m5s3hnM98jznnEBGR8NLA6wJERCT4FO4iImFI4S4iEoYU7iIiYUjhLiIShqK8LgAgNjbWJSUleV2GiEhIWbNmzRHnXLuqHqsX4Z6UlERGRobXZYiIhBQzy/ymx7RbRkQkDCncRUTCkMJdRCQMKdxFRMKQwl1EJAwp3EVEwpDCXUQkDCncRUQ8kFt4ht8t38nuvFO18vvrxZeYREQiQWWl48s9R0hNy+Sv2/KodI52LZvQI65F0NelcBcRqWUFRaW8teYA89Oz2HfkNG2aN+aei7oxcUQCXdpE18o6Fe4iIrVkQ3YB89Iy+Z8NBykpr2RY4nn8aExPrhnQniZRDWt13Qp3EZEgOlNawf9sOMi8tEw25RQS3bghNw/rzKQRifTt2KrO6lC4i4gEwd78U6SmZfHWmmxOFJfTK74FT43rx41DOtGyaaM6r0fhLiJSQ+UVlfx122FS07L4YvcRohoYV/dvz+SRiaR0bYOZeVabwl1E5BwdPlHMwlVZvLEqm0MniukY05T/d2UvbhvehbiWTb0uD1C4i4hUi3OOr/YcZV5aJn/ZepiKSsfFvdrx9A39ufT8dkQ1rF9fG1K4i4h8i8IzZby95gCp6Z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34HbAV2ASM97rmOhhzX+BLfJ0064Erva45wPEuBHKBMnxb6dOB+4D7znqN/+T/e2wKxvta0w+IiIShUNktIyIi50DhLiIShhTuIiJhSOEuIhKGFO4iImFI4S4iEoYU7iIiYej/A00ekQ5JJWrrAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 一些参数. 来自15.2\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "\n",
    "x0 = np.array([41, 49, 61, 78, 96, 104], dtype=np.float)\n",
    "plt.plot(np.linspace(0, 1, x0.shape[0]), x0)\n",
    "plt.show()\n",
    "lamb = np.array([x0[i] / x0[i+1] for i in range(x0.shape[0]-1)])\n",
    "Theta = (np.exp(-2/(x0.shape[0]+1)), np.exp(2/(x0.shape[0]+2)))\n",
    "OK = [i <= Theta[1] and i >= -Theta[0] for i in lamb]\n",
    "x1 = np.array([x0[:i].sum() for i in range(1, x0.shape[0]+1)])\n",
    "alpha1_x0 = np.array([x0[i] - x0[i-1] for i in range(1, x0.shape[0])])\n",
    "z1 = np.array([(x1[i]+x1[i+1])/2 for i in range(x1.shape[0]-1)])\n",
    "B = np.array(np.c_[-x0[1:], -z1, np.ones(z1.shape[0])])\n",
    "Y = alpha1_x0\n",
    "u = np.matmul(np.linalg.inv(np.matmul(B.T, B)), np.matmul(B.T, Y))\n",
    "a1, a2, b = u[0], u[1], u[2]\n",
    "x1_t = lambda k: (x0[0] - b/a) * np.exp(-a*k) + b/a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "得到带参符号解: Eq(x1_t(t), C1*exp(t*(-a1 - sqrt(a1**2 - 4*a2))/2) + C2*exp(t*(-a1 + sqrt(a1**2 - 4*a2))/2) + b/a2)\n",
      "待定常数:  {C2, C1}\n",
      "关于待定常数的多元方程组:\n",
      "[Eq(41, C1 + C2 + b/a2), Eq(x1_t(6), C1*exp(-3*a1 - 3*sqrt(a1**2 - 4*a2)) + C2*exp(-3*a1 + 3*sqrt(a1**2 - 4*a2)) + b/a2)]\n",
      "解得待定常数: {C1: ((41*a2 - b)*exp(3*a1 + 6*sqrt(a1**2 - 4*a2)) - (a2*x1_t(6) - b)*exp(6*a1 + 3*sqrt(a1**2 - 4*a2)))*exp(-3*a1)/(a2*(exp(6*sqrt(a1**2 - 4*a2)) - 1)), C2: -((41*a2 - b)*exp(3*a1) - (a2*x1_t(6) - b)*exp(6*a1 + 3*sqrt(a1**2 - 4*a2)))*exp(-3*a1)/(a2*(exp(6*sqrt(a1**2 - 4*a2)) - 1))}\n",
      "最终解: x1_t(t) = b/a2 - ((41*a2 - b)*exp(3*a1) - (a2*x1_t(6) - b)*exp(6*a1 + 3*sqrt(a1**2 - 4*a2)))*exp(-3*a1)*exp(t*(-a1 + sqrt(a1**2 - 4*a2))/2)/(a2*(exp(6*sqrt(a1**2 - 4*a2)) - 1)) + ((41*a2 - b)*exp(3*a1 + 6*sqrt(a1**2 - 4*a2)) - (a2*x1_t(6) - b)*exp(6*a1 + 3*sqrt(a1**2 - 4*a2)))*exp(-3*a1)*exp(t*(-a1 - sqrt(a1**2 - 4*a2))/2)/(a2*(exp(6*sqrt(a1**2 - 4*a2)) - 1))\n"
     ]
    }
   ],
   "source": [
    "# sympy的一个例子\n",
    "# 参考: https://blog.csdn.net/and_w/article/details/80160033\n",
    "import sympy\n",
    "\n",
    "sympy.init_printing\n",
    "# 定义符号常量x 与 f(x)\n",
    "t = sympy.Symbol('t')\n",
    "a1, a2, b = sympy.symbols('a1, a2, b')\n",
    "x1_t = sympy.Function('x1_t')\n",
    "# 微分方程ode\n",
    "ode = sympy.Eq(x1_t(t).diff(t, t) + a1*x1_t(t).diff(t) + a2*x1_t(t), b)\n",
    "init1 = sympy.Eq(x1_t(0), x1[0])\n",
    "init2 = sympy.Eq(x1_t(1), x1[1])\n",
    "# 调用dsolve函数,返回一个Eq对象，hint控制精度\n",
    "ode_sol = sympy.dsolve((ode), x1_t(t))\n",
    "print('得到带参符号解:', ode_sol)\n",
    "\n",
    "# 初始条件字典\n",
    "x1_to_value = {x1_t(0): 41, x1_t(x1.shape[0]-1): x1[-1]}\n",
    "# 确定待定常数集\n",
    "known_params = {a1, a2, b, t}\n",
    "free_params = ode_sol.free_symbols - set(known_params)\n",
    "# 将初始条件带入微分方程的后得到的多元方程\n",
    "C_eqs = [sympy.Eq(ode_sol.lhs.subs(t, 0).subs(x1_to_value), ode_sol.rhs.subs(t, 0)),\n",
    "         sympy.Eq(ode_sol.lhs.subs(t, x1.shape[0]).subs(x1_to_value), ode_sol.rhs.subs(t, x1.shape[0]))\n",
    "        ]\n",
    "print('待定常数: ', free_params)\n",
    "print('关于待定常数的多元方程组:', C_eqs, sep='\\n')\n",
    "sol_params = sympy.solve(C_eqs, free_params)\n",
    "print('解得待定常数:', sol_params)\n",
    "final_sol_eq = sympy.Eq(ode_sol.lhs, ode_sol.rhs.subs(sol_params))\n",
    "print('最终解:', final_sol_eq.lhs, '=', final_sol_eq.rhs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAagAAAEYCAYAAAAJeGK1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAgAElEQVR4nO3df5DV9X3v8eeLBXSNPwBFIgsGo8RGY4ORone8c6/VhKXJnSvJmISkNzItM2SsuW2nudxCO3e05nrVkNRbm8aOqVS0iT+uscokGkqxSZrUoGswAhqEBKOwVNBlEcOC7PK+f3w/R84u5+yes3t+7dnXY+bM+e7nfD/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
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# scipy.integrate.RK45\n",
    "# 用龙格库塔法解一阶微分方程组\n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from scipy.integrate import RK45\n",
    "\n",
    "\n",
    "def funcs(t, x):\n",
    "    dxdt = np.zeros(2)\n",
    "    a = 1e-8\n",
    "    dxdt[0] = 0.05*x[0]*(1-x[0]/150000)-a*x[0]*x[1];\n",
    "    dxdt[1] = 0.08*x[1]*(1-x[1]/400000)-a*x[0]*x[1];\n",
    "    return dxdt\n",
    "\n",
    "\n",
    "t0 = 0\n",
    "y0 = [5000, 70000]\n",
    "t_bound = 1000\n",
    "\n",
    "rk45 = RK45(fun=funcs, t0=t0, y0=y0, t_bound=t_bound)\n",
    "\n",
    "t = []\n",
    "x = [[], []]\n",
    "\n",
    "while rk45.status == 'running':\n",
    "    rk45.step()\n",
    "    t.append(rk45.t)\n",
    "    x[0].append(rk45.y[0])\n",
    "    x[1].append(rk45.y[1])\n",
    "plt.subplot(1, 2, 1)\n",
    "plt.plot(t, x[0], color='orange')\n",
    "plt.plot(t, x[1], color='b')\n",
    "plt.xlabel(u't')\n",
    "plt.ylabel(u'x')\n",
    "plt.subplot(1, 2, 2)\n",
    "plt.scatter(x[0], x[1])\n",
    "plt.xlabel(u'x_1')\n",
    "plt.ylabel(u'x_2')\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
